<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--
 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
 * Copyright (C) 2003-2007 Frederico Caldeira Knabben
 *
 * == BEGIN LICENSE ==
 *
 * Licensed under the terms of any of the following licenses at your
 * choice:
 *
 *  - GNU General Public License Version 2 or later (the "GPL")
 *    http://www.gnu.org/licenses/gpl.html
 *
 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
 *    http://www.gnu.org/licenses/lgpl.html
 *
 *  - Mozilla Public License Version 1.1 or later (the "MPL")
 *    http://www.mozilla.org/MPL/MPL-1.1.html
 *
 * == END LICENSE ==
 *
 * This page shows all resources available in a folder in the File Browser.
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<link href="browser.css" type="text/css" rel="stylesheet" />
	<script type="text/javascript" src="js/common.js"></script>
	<script type="text/javascript">

var oListManager = new Object() ;

oListManager.Clear = function()
{
	document.body.innerHTML = '' ;
}

oListManager.GetFolderRowHtml = function( folderName, folderPath )
{
	// Build the link to view the folder.
	var sLink = '<a href="#" onclick="OpenFolder(\'' + folderPath.replace( /'/g, '\\\'') + '\');return false;">' ;

	return '<tr>' +
			'<td width="16">' +
				sLink +
				'<img alt="" src="images/Folder.gif" width="16" height="16" border="0"></a>' +
			'</td><td nowrap colspan="2">&nbsp;' +
				sLink +
				folderName +
				'</a>' +
		'</td></tr>' ;
}

oListManager.GetFileRowHtml = function( fileName, fileUrl, fileSize )
{
	// Build the link to view the folder.
	var sLink = '<a href="#" onclick="OpenFile(\'' + fileUrl.replace( /'/g, '\\\'') + '\');return false;">' ;

	// Get the file icon.
	var sIcon = oIcons.GetIcon( fileName ) ;

	return '<tr>' +
			'<td width="16">' +
				sLink +
				'<img alt="" src="images/icons/' + sIcon + '.gif" width="16" height="16" border="0"></a>' +
			'</td><td>&nbsp;' +
				sLink +
				fileName +
				'</a>' +
			'</td><td align="right" nowrap>&nbsp;' +
				fileSize +
				' KB' +
		'</td></tr>' ;
}

function OpenFolder( folderPath )
{
	// Load the resources list for this folder.
	window.parent.frames['frmFolders'].LoadFolders( folderPath ) ;
}

function OpenFile( fileUrl )
{
	
	//锟斤拷4锟斤拷锟斤拷锟斤拷应锟矫斤拷锟斤拷锟轿伙拷酶锟轿拷锟斤拷位锟斤拷
	//fileUrl = window.location.protocol+"//"+window.location.host+fileUrl;
	var parent = window.top.opener;
	if(parent!=null){
		parentDocument = parent.document;
		try{
			if(parentDocument.getElementById("uploadPic")!=null && parentDocument.getElementById("pic").value==0)
			{
				parentDocument.getElementById("uploadPic").value=fileUrl;
			}
			if(parentDocument.getElementById("uploadPic2")!=null && parentDocument.getElementById("pic").value==1)
			{
				parentDocument.getElementById("uploadPic2").value=fileUrl;
			}
			if(parentDocument.getElementById("fileico2")!=null && parentDocument.getElementById("isfile").value==0){
				parentDocument.getElementById("fileico2").value=fileUrl;
			}
			if(parentDocument.getElementById("documentPicurl3")!=null && parentDocument.getElementById("isfile").value==1){
				imgdiv=parentDocument.getElementById("imgs");
				//保存url
				documentPicurl2Obj=parentDocument.getElementById("documentPicurl3");
				documentPicurl2Obj.value=documentPicurl2Obj.value+fileUrl+";";
				//alert(documentPicurl2Obj.value);
				id=Date.parse(new Date());
				imgdiv.innerHTML=imgdiv.innerHTML+"<span id='addImg"+id+"' style='display:block'><table><tr><td><img src='"+fileUrl+"' width='200' height='180' ></td></tr><tr><td align='center'><img src='../images/sc.gif' style='cursor:hand' onclick='delImg(\""+fileUrl+"\",\"addImg"+id+"\")'></td></tr></table></span>";
							
			}
			if(parentDocument.getElementById("selectLOGO")!=null){
				parentDocument.getElementById("selectLOGO").value=fileUrl;
			}else if(parentDocument.getElementById("specialImg")!=null){
				parentDocument.getElementById("specialImg").value=fileUrl;
			}else if(parentDocument.getElementById("documentPicurl")!=null){
				parentDocument.getElementById("documentPicurl").value=fileUrl;
			}else if(parentDocument.getElementById("documentPicurl2")!=null){
				imgdiv=parentDocument.getElementById("imgs");
				//淇濆瓨url
				documentPicurl2Obj=parentDocument.getElementById("documentPicurl2");
				documentPicurl2Obj.value=documentPicurl2Obj.value+fileUrl+";";
				//alert(documentPicurl2Obj.value);
				id=Date.parse(new Date());
				imgdiv.innerHTML=imgdiv.innerHTML+"<span id='addImg"+id+"' style='display:block'><table><tr><td><img src='"+fileUrl+"' width='200' height='180' ></td></tr><tr><td align='center'><img src='../images/sc.gif' style='cursor:hand' onclick='delImg(\""+fileUrl+"\",\"addImg"+id+"\")'></td></tr></table></span>";
							
			}else if(parentDocument.getElementById("nameORico")!=null){//锟侥硷拷锟斤拷锟斤拷
				var nameORico = parentDocument.getElementById("nameORico");
				if(nameORico.value=="name"){
					var mutifile = parentDocument.getElementById("multiFiles");
					if(mutifile!=null&&mutifile.checked&&parentDocument.getElementById("filename").value!=""){
						parentDocument.getElementById("filename").value +="|"+fileUrl;	
					}else{
						parentDocument.getElementById("filename").value = fileUrl;	
					}
					
				}else if(nameORico.value=="ico"){
					parentDocument.getElementById("fileico").value = fileUrl;	
				}
			}
			
			var basePath=parentDocument.getElementById("basePath");
			var img=parentDocument.getElementById("imgurl");			
			if(img != null && basePath !=null)
			{	
				img.src=basePath.value+fileUrl;
						
			}
		}catch(e){
			window.top.close();
		}
		window.top.close();
	}
	//锟斤拷锟斤拷锟斤拷锟睫革拷
	if(window.top.opener!=null){//锟斤拷锟斤拷fck锟斤拷锟斤拷锟斤拷锟绞�
		window.top.opener.SetUrl(  fileUrl  ) ;
		window.top.close() ;
		window.top.opener.focus() ;
	}else{ 
		window.returnValue = fileUrl ; 
		window.top.close() ;	
	}	
}

function LoadResources( resourceType, folderPath )
{
	oListManager.Clear() ;
	oConnector.ResourceType = resourceType ;
	oConnector.CurrentFolder = folderPath ;
	oConnector.SendCommand( 'GetFoldersAndFiles', null, GetFoldersAndFilesCallBack ) ;
}

function Refresh()
{
	LoadResources( oConnector.ResourceType, oConnector.CurrentFolder ) ;
}

function GetFoldersAndFilesCallBack( fckXml )
{
	if ( oConnector.CheckError( fckXml ) != 0 )
		return ;

	// Get the current folder path.
	var oFolderNode = fckXml.SelectSingleNode( 'Connector/CurrentFolder' ) ;
	if ( oFolderNode == null )
	{
		alert( 'The server didn\'t reply with a proper XML data. Please check your configuration.' ) ;
		return ;
	}
	var sCurrentFolderPath	= oFolderNode.attributes.getNamedItem('path').value ;
	var sCurrentFolderUrl	= oFolderNode.attributes.getNamedItem('url').value ;

//	var dTimer = new Date() ;

	var oHtml = new StringBuilder( '<table id="tableFiles" cellspacing="1" cellpadding="0" width="100%" border="0">' ) ;

	// Add the Folders.
	var oNodes ;
	oNodes = fckXml.SelectNodes( 'Connector/Folders/Folder' ) ;
	for ( var i = 0 ; i < oNodes.length ; i++ )
	{
		var sFolderName = oNodes[i].attributes.getNamedItem('name').value ;
		oHtml.Append( oListManager.GetFolderRowHtml( sFolderName, sCurrentFolderPath + sFolderName + "/" ) ) ;
	}

	// Add the Files.
	oNodes = fckXml.SelectNodes( 'Connector/Files/File' ) ;
	for ( var j = 0 ; j < oNodes.length ; j++ )
	{
		var oNode = oNodes[j] ;
		var sFileName = oNode.attributes.getNamedItem('name').value ;
		var sFileSize = oNode.attributes.getNamedItem('size').value ;

		// Get the optional "url" attribute. If not available, build the url.
		var oFileUrlAtt = oNodes[j].attributes.getNamedItem('url') ;
		var sFileUrl = oFileUrlAtt != null ? oFileUrlAtt.value : sCurrentFolderUrl + sFileName ;

		oHtml.Append( oListManager.GetFileRowHtml( sFileName, sFileUrl, sFileSize ) ) ;
	}

	oHtml.Append( '<\/table>' ) ;

	document.body.innerHTML = oHtml.ToString() ;

//	window.top.document.title = 'Finished processing in ' + ( ( ( new Date() ) - dTimer ) / 1000 ) + ' seconds' ;

}

window.onload = function()
{
	window.top.IsLoadedResourcesList = true ;
}
	</script>
</head>
<body class="FileArea" bottommargin="10" leftmargin="10" topmargin="10" rightmargin="10">
</body>
</html>
